<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{asset('/css/web/user/shop_brand.css')}}">
    <link rel="stylesheet" href="{{asset('/css/web/user/contract_msg.css')}}">
    <link rel="stylesheet" href="{{asset('/css/web/user/contract.css')}}">
      @include('UEditor::head')  
</head>
<body>
@include('web.layout.header')
@include('web.layout.user_tab')
<div class="base_member_content">
    <div class="w1200">
        @include('web.layout.seller_nav')
        <div class="nav_right flr">
            <div class="base_content">
                <div class="line_title" style="border-bottom:0;">合同信息</div>
                <div class="content">
                    <div class="contract_top">
                        <ul>
                            <li class="sign_contract">1、基础信息</li>
                            <li class="first">2、签署合同</li>
                            <li>3、确认成功</li>
                        </ul>
                    </div>
                    <div class="contracts_choose_modle">
                        <p class="choose_modle_tit">请选择合同模板</p>
                       
                            <select class="select fl" id='contract_type' name='contract_type'>
                                <option value='-1'>请选择合同模板</option>
                                 @if($contracts)
                        @foreach($contracts as $c)
                                <option value='{{$c['id']}}'  data-content="{{$c['content']}}" @if($c['is_default']==1) selected="selected" @endif>{{$c['name']}}</option>
                         @endforeach
                         @endif
                            </select>
                        
                        <a href="/member/seller/contracts">编辑我的模板</a>
                    </div>
                    <form action="/member/seller/order_contract/contract_post" id="contracts_info" method="post" style="display:none;">
                    <input type="hidden" value="{{$base_info}}" name="base_info" />
                      <input type="hidden" value="{{$order_id}}" name="order_id" />
                      <input type="hidden" value="{{$qid}}" name="qid" />
                        <div class="contract_choose" style="display:block;">
                            <div class="contract_title">
                                <span id="contract_title"></span>
                            </div>
                            <div class="contract_con">
                                @if(isset($type) && $type == 'put')
                                    {{method_field("PUT")}}
                                @endif
                                {!!  csrf_field() !!}
                                <input type="hidden" name="id" value="{{old('id')}}" />
                                <div class="contract_id_time">
                                     <div class="contract_id fl contract_people">合同编号：
                                        <span>
                                            {{$contract_code}}
                                        </span>
                                    </div>  
                                   <!-- <div class="contract_time fr">日期：<span>@if (isset($contracts['created_at'])){{$contracts['created_at']}} @else {{ date('Y-m-d H:i:s',time()) }}@endif</span></div>--> 
                                    <div class="clear"></div>
                                </div>
                                <div class="contract_people">甲方：@if(isset($buyer_company['company_name'])){{$buyer_company['company_name']}}@endif</div>
                                <div class="contract_people">乙方：@if(isset($seller_company['company_name'])){{$seller_company['company_name']}}@endif</div>
                                <div class="contract_word">根据《中华人民共和国合同法》及相关法律法规的规定，甲乙双方在平等、自愿、公平、协商一致的基础上，就甲方委托乙方提供服务的有关事宜达成如下协议：</div>
                        
                                <div class="contract_word">合同条例：</div>

                                <div class="contract_prompt">
                                    @if(!isset($contracts['content']))
                                  <!--   <textarea name="content" class="prompt">
 
                                    </textarea> -->
                                     <script id="content" name="content"  style="min-height:300px;" type="text/plain"> </script> 
                                    @else
                                        <textarea name="content" class="prompt">
                                            {{$contracts['content']}}
                                        </textarea>
                                    @endif
                                    @if($errors->has('content'))
                                        <span class="jm_error" style="display: inline;clear: both;">{{$errors->first('content')}}</span>
                                    @endif
                                </div>
                                <div class="contract_st_box">
                                    <div class="contract_seal_box fl">
                                        <div class="seal_people">甲方：@if(isset($buyer_company['company_name'])){{$buyer_company['company_name']}}@endif</div>
                                        <div class="seal">（盖章）</div>
                                    </div>
                                    <div class="contract_seal_box fr">
                                        <div class="seal_people">乙方：<span>@if(isset($seller_company['company_name'])){{$seller_company['company_name']}}@endif</span></div>
                                        <div class="seal">（盖章）</div>
                                    </div>
                                </div>
                            </div>
                            <div class="btn_box">
                            <input type="hidden" name="contract_code" value="{{$contract_code}}" />
                            <input type="hidden" name="buyer_name" value="@if(isset($buyer_company['company_name'])){{$buyer_company['company_name']}}@endif" />
                            <input type="hidden" name="seller_name" value="@if(isset($seller_company['company_name'])){{$seller_company['company_name']}}@endif" />
                            <input type="hidden" name="buyer_user_id" value="{{$buyer_user_id}}" />
                                <button class="btn_confirm" type="submit">合同签署</button>
                            </div>
                        </div>
                    </form>
                    <div class="contract_no_choose"  >
                        <img class="choose_img" src="{{asset('/img/web/user/modle.png')}}" alt="">
                        <p>您还没有选择合同模板</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@include('web.layout.footer')
<script>
$(function(){
	$("#contract_type").change(function(){
		if($(this).val() != -1 ){
			$("#contract_title").html($("#contract_type").find("option:selected").text());
			$("#contracts_info").show();

			  ue_detail.ready(function() {
			        ue_detail.execCommand('serverparam', '_token', '{{ csrf_token() }}'); // 设置 CSRF token.
			        ue_detail.setContent($("#contract_type").find("option:selected").attr("data-content"));
			    });
		
			$(".contract_no_choose").hide();
		}else{
			$("#contracts_info").hide();
			$(".contract_no_choose").show();
		}
		
	});

    //var ue_detail = UE.getEditor('content', { initialFrameWidth: null });

    var ue_detail = UE.getEditor('content', {
        toolbars: [
            [
                'fullscreen'  , 'bold', 'italic', 'underline', 'blockquote', '|',
                'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', '|',
                'paragraph', 'fontfamily', 'fontsize', '|',
                'justifyleft', 'justifycenter', 'justifyright', '|',
                'link', 'unlink','horizontal', '|',
            ]
        ],
        initialFrameHeight: 500,
        initialFrameWidth: null,
        initialStyle:'p{font-size:10px; }'
    });
    
    
    ue_detail.ready(function() {
        ue_detail.execCommand('serverparam', '_token', '{{ csrf_token() }}'); // 设置 CSRF token.
    });

    if($("#contract_type").find("option:selected").val() != -1){
    	$("#contract_title").html($("#contract_type").find("option:selected").text());
		$("#contracts_info").show();

		  ue_detail.ready(function() {
		        ue_detail.execCommand('serverparam', '_token', '{{ csrf_token() }}'); // 设置 CSRF token.
		        ue_detail.setContent($("#contract_type").find("option:selected").attr("data-content"));
		    });
	
		$(".contract_no_choose").hide();
    }
    
	 $('.btn_confirm').click(function(){
	        layer.confirm('是否签署合同？', {
	            btn: ['确认', '取消'] //可以无限个按钮
	        }, function (index) {
	            $.ajax({
	                url: "/member/seller/order_contract/contract_post",
	                type: 'post',
	                dataType: 'json',
	                data: $("#contracts_info").serializeArray(),
	                success: function (data) {
	                    if (1 == data.status) {
	                        layer.alert("签署成功", {
	                            icon: 1
	                        }, function () {
	                            location.href='/member/seller/order_contract/contract_cost?order_id='+data.order_id;
	                        });
	                    } else {
	                        layer.alert(data.msg, {
	                            icon: 2
	                        });
	                    }
	                }
	            });
	        }, function (index, layero) {
	            layer.close(index);
	        });
	        return false;

	 });   
});
</script>
</body>
</html>